package org.darcy.config.bean.satoken;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.darcy.entity.privilege.SysRole;
import org.darcy.framework.constant.SysConstant;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;

public class StpInterfaceImpl implements StpInterface {

	@Override
	public List<String> getPermissionList(Object loginId, String loginType) {
		List<String> list = new ArrayList<>();
		if (!StpUtil.isLogin()) {
			return list;
		}

		SaSession session = StpUtil.getSessionByLoginId(loginId);
		Object aclObj = session.get(SysConstant.LOGIN_MENU_LIST);
		if (aclObj == null) {
			return list;
		}

		return list;
	}

	@Override
	public List<String> getRoleList(Object loginId, String loginType) {
		List<String> list = new ArrayList<>();
		if (StpUtil.isLogin()) {
			SaSession session = StpUtil.getSessionByLoginId(loginId);
			Object roleObj = session.get(SysConstant.LOGIN_ROLE_LIST);
			if (roleObj != null) {
				List<SysRole> roles = (List<SysRole>) roleObj;
				if (CollectionUtils.isNotEmpty(roles)) {
					roles.forEach(role -> list.add(role.getSn()));
				}
			}
		}
		return list;
	}
}
